package com.controller;

import com.orm.Db;
import com.orm.WebServiceEntity;

import java.sql.ResultSet;
import java.util.ArrayList;

/**
 * Created by lirance on 16/5/10.
 */
public class GetServiceList {
    public ArrayList GetServiceLists() throws Exception {
        String sql = "select * from webService";
        ArrayList<WebServiceEntity> serviceCalls = new ArrayList<>();

        ResultSet resultSet = Db.getInstance().executeQuery(sql);
        int i = 0;
        while (resultSet.next()) {
            i++;
            WebServiceEntity serCall = new WebServiceEntity();
            serCall.setWsId(resultSet.getInt("wsId"));
            serCall.setClusteNam(resultSet.getString("clusteNam"));
            serCall.setClusteNum(resultSet.getString("clusteNum"));
            serCall.setLocation(resultSet.getString("location"));
            serCall.setProName(resultSet.getString("proName"));
            serCall.setWsAddress(resultSet.getString("wsAddress"));
            serCall.setWsName(resultSet.getString("wsName"));
            serviceCalls.add(serCall);
        }
        resultSet.close();
        return serviceCalls;
    }

    public ArrayList GetServiceListsBywsId(int wsid) throws Exception {
        String sql = "select * from webService where wsId = " + wsid;
        ArrayList<WebServiceEntity> serviceCalls = new ArrayList<>();

        ResultSet resultSet = Db.getInstance().executeQuery(sql);
        int i = 0;
        while (resultSet.next()) {
            i++;
            WebServiceEntity serCall = new WebServiceEntity();
            serCall.setWsId(resultSet.getInt("wsId"));
            serCall.setClusteNam(resultSet.getString("clusteNam"));
            serCall.setClusteNum(resultSet.getString("clusteNum"));
            serCall.setLocation(resultSet.getString("location"));
            serCall.setProName(resultSet.getString("proName"));
            serCall.setWsAddress(resultSet.getString("wsAddress"));
            serCall.setWsName(resultSet.getString("wsName"));
            serviceCalls.add(serCall);
        }
        resultSet.close();
        return serviceCalls;
    }

    public ArrayList GetServiceListsBywsclusteNam(String clusteName) throws Exception {
        String sql = "select * from webService where clusteNam = '" + clusteName + "'";
        ArrayList<WebServiceEntity> serviceCalls = new ArrayList<>();

        ResultSet resultSet = Db.getInstance().executeQuery(sql);
        int i = 0;
        while (resultSet.next()) {
            i++;
            WebServiceEntity serCall = new WebServiceEntity();
            serCall.setWsId(resultSet.getInt("wsId"));
            serCall.setClusteNam(resultSet.getString("clusteNam"));
            serCall.setClusteNum(resultSet.getString("clusteNum"));
            serCall.setLocation(resultSet.getString("location"));
            serCall.setProName(resultSet.getString("proName"));
            serCall.setWsAddress(resultSet.getString("wsAddress"));
            serCall.setWsName(resultSet.getString("wsName"));
            serviceCalls.add(serCall);
        }
        resultSet.close();
        return serviceCalls;
    }

}
